const Config = {
    CONFIG_ENV: process.env.VUE_APP_CONFIG
}

const mockCreator = (dataPromise, enable, envs = ['dev']) => {
  return (dataKey) => {
    return (target, _key, descriptor) => {
      const method = descriptor.value
      descriptor.value = async (...args) => {
        if (envs.indexOf(Config.CONFIG_ENV) >= 0 && enable) {
          const data = await dataPromise
          return typeof data[dataKey] === 'function' ? data[dataKey](...args) : data[dataKey]
        } else {
          return method.apply(target, args)
        }
      }
      return descriptor
    }
  }
}

export default mockCreator